package com.matt.domain;

import com.matt.foundation.constant.NoticeMessageConstant;
import com.matt.commons.model.Domain;
import com.matt.commons.model.Model;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2018/3/22
 * *******************************
 */
@Entity
@Table(name = "notice_message")
@Data
@EqualsAndHashCode(callSuper = true)
public class NoticeMessage extends Domain{

    @Column(columnDefinition = " int default 0 COMMENT '提醒消息类型' ")
    private Integer category=0;

    @Column(columnDefinition = " varchar(1024) COMMENT '提醒信息' ")
    private String message;

    @Column(columnDefinition = " varchar(1024) COMMENT '跳转链接' ")
    private String url;

    @Column(columnDefinition = " varchar(32)  COMMENT '对应domain id' ")
    private String linkId;

    @Column(columnDefinition = " varchar(32)  COMMENT '接受人id' ")
    private String receiveId;

    @Column(columnDefinition = " varchar(32)  COMMENT '园区id' ")
    private String areaId;

    @Column(columnDefinition = " int default 0 COMMENT '计数' ")
    private Integer number=0;

    @Column(columnDefinition = " varchar(100)  COMMENT '扩展字段' ")
    private String ext;

    @Column(columnDefinition = " int default 0 COMMENT '过期状态' ")
    private Integer dueStatus = 0;

    @Column(columnDefinition = " datetime COMMENT '过期时间' ")
    private Date dueDate;

    @Column(columnDefinition = " datetime DEFAULT NOW() COMMENT '最后修改时间' ")
    private Date lastModified = new Date();


    public static NoticeMessage of(String message, NoticeMessageConstant.Category category, String linkId, String receiveId, String areaId){
        NoticeMessage noticeMessage =new NoticeMessage();
        noticeMessage.setCategory(category.codeOf());
        noticeMessage.setMessage(message);
        noticeMessage.setLinkId(linkId);
        noticeMessage.setAreaId(areaId);
        noticeMessage.setReceiveId(receiveId);
        return noticeMessage;
    }
}
